package com.admin.config.RabbitMQ;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 张子艺
 * @packge com.currency.admin.config.RabbitMQ
 * @data 2019-01-16 15:33
 * @project currencycloud
 */
@Configuration
public class QueryInit {
    /**
     * @apiNote 定义扇出（广播）交换器  因为是队列  所以 应该发送一整个数据包到一个队列 而不是data moeny end 分开
     * Topic交换器  在定义队列的时候 就指定某个队列的key   发送消息时候 指定发送给哪个key的队列  接受的时候 只需要接受该key的队列名即可
     *              ------------队列1
     *              |
     * 消息----交换器------------队列2
     *              |
     *              -----------队列3
     */
    @Bean
    public FanoutExchange topicExchange() {
        return new FanoutExchange("fanout-exchange");
    }
    @Bean
    public Binding binding0(FanoutExchange topicExchange, Queue socketDataOne) {
        System.err.println("正在把队列"+socketDataOne.getName()+"绑定在交换器上");
        return BindingBuilder.bind(socketDataOne).to(topicExchange) ;
    }
    @Bean
    public Binding binding1(FanoutExchange topicExchange, Queue socketDataTwo) {
        System.err.println("正在把队列"+socketDataTwo.getName()+"绑定在交换器上");
        return BindingBuilder.bind(socketDataTwo).to(topicExchange) ;
    }



    @Bean
    public Queue socketDataOne() {
        System.err.println("socketDataOne");
        return new Queue("socketDataOne");
    }
    @Bean
    public Queue socketDataTwo() {
        System.err.println("正在注入socketDataTwo消息队列");
        return new Queue("socketDataTwo");
    }

}
